package io.github.yuegod.clean.acl.configuration;


import io.github.yuegod.clean.acl.ApiAclClient;
import io.github.yuegod.clean.acl.client.Client;
import io.github.yuegod.clean.acl.property.ApiAclClientProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.logging.Logger;

/**
 * @author quziwei
 * @date 2021/8/5 8:42
 **/
@EnableConfigurationProperties({ApiAclClientProperties.class})
@Configuration
@ConditionalOnProperty(
        name = "io.github.yuegod.clean.acl.configuration.ApiAclClientConfiguration",
        prefix = "api.acl.client.type",
        havingValue = "io.github.yuegod.clean.acl.Client",
        matchIfMissing = true)
public class ApiAclClientAutoConfiguration {


    @Bean
    public ApiAclClient apiAclClient(ApiAclClientProperties apiAclClientProperties) {
        Class<ApiAclClient> type = apiAclClientProperties.getType();
        try {
            return type.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return new Client();
    }

}
